// pages/order/order.js

import request from "../../utils/request.js";
import local from "../../utils/local";
import nav from "../../utils/nav.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    appid: 'wx15a7538fa77ddfc0',
    recordList: [],
    memberID: '',
    recordKey: '',
    isTriggered: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const memberID = local.getLocal('memberID');
    this.setData({
      memberID: memberID,
    })
    // this.getPaipanitemsservice()
  },

  // bindKeyInput(e) {
  //   this.setData({
  //     recordKey: e.detail.value || '',
  //   })
  // },

  /**
   * 获取搜索相关数据
   */
  // handleToComfirm(event) {
  //   if (this.data.loading) return
  //   wx.pageScrollTo({
  //     scrollTop: 0
  //   })
  //   this.getPaipanitemsservice()
  // },


  /**
   * 获取订单数据
   */
  getPaipanitemsservice() {
    var that = this;
    let userInfoDic = {
      "user": this.data.appid,
      "eventCode": "314"
    }
    let paiPanItemsStuctDic = {
      "memberID": this.data.memberID,
      "custName": this.data.recordKey,
    }
    let dic = {
      userInfo: userInfoDic,
      paiPanItemsStuct: paiPanItemsStuctDic,
    }
    console.log(dic)
    request.get('/paipanitemsservice', {param: dic}).then((res)=> {
      console.log(res)
      const returnCode = res.RETURN
      if (returnCode == 1) {
        that.setData({
          recordList: res.PAIPAN_LIST,
          isTriggered: false,
        })
      }
      
    })
  },

  onClickToRecordDetail(e) {
    const code = e.detail
    let object = {
      code: code
    }
    let jsonStr = JSON.stringify(object)
    let data = encodeURIComponent(jsonStr)
    nav.navigateTo('/order/detail/order-detail?data='+data)
  },

  onClickToRecordDelete(e) {
    console.log(e)
    const code = e.detail
    const that = this
    wx.showModal({
      title: '温馨提示',
      content: '是否删除订单?',
      complete: (res) => {
        if (res.cancel) {
        }
        if (res.confirm) {
          that.deletePaipanitemsservice(code)
        }
      }
    })
    
  },

  deletePaipanitemsservice(code) {
    var that = this;
    let userInfoDic = {
      "user": this.data.appid,
      "eventCode":"315"
    }
    let paiPanItemsStuctDic = {
      "surName": code,
      "memberID": this.data.memberID
    }
    let dic = {
      userInfo: userInfoDic,
      paiPanItemsStuct: paiPanItemsStuctDic,
    }
    console.log(dic)
    request.get('/paipanitemsservice',  {param: dic}).then((res)=> {
      console.log(res)
      const returnCode = res.RETURN
      if (returnCode == 1) {
        that.getPaipanitemsservice()
      }
    })
  },

  refreshHandler() {
    this.getPaipanitemsservice()
  },
  
})